﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>员工管理</title>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	
	<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
	
	<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
	<script type="text/javascript">
	  $(function(){
	    // alert("页面加载函数");
	     querys(1);
	     
	     $("#query").click(function(){
	        
	        querys(1);
	     });
	     
	     //分页加动作
		   $("body").on("click","#pagediv li a",function(){
		
		     var pp = $(this).attr("name");
		   
		     querys(pp);
		     });
		     
		    //页面加载显示所有部门
		     $.getJSON("dept/list.action","",function(res){
		        //alert("部门："+res.length);
		        for(var i=0;i<res.length;i++)
		        {
		            $("#dep").append("<option value='"+res[i].de_id+"'>"+res[i].de_name+"</option>");
		        }
		     });
		     
	  });
	  function toTime(timestamp) {
		   var date = new Date(timestamp);
		   Y = date.getFullYear() + '-';
		   M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
		   D = date.getDate() + ' ';
		   h = date.getHours() + ':';
		   m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':';
		   s = (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds());
		   return Y+M+D+h+m+s;
		}
	  function querys(pp)
	  {
	    var str=$("#queryform").serialize()+"&page="+pp;
	   // alert(str);
	    $.getJSON("emp/querylist.action",str,function(pbean){
	        $("#empbody").html("");
	       for(var i=0;i<pbean.list.length;i++)
	       {
	         var emp=pbean.list[i];
	         var trs=$("<tr class='text-c'></tr>");
	         trs.append("<td>"+emp.us_id+"</td>");
	         trs.append("<td>"+emp.us_name+"</td>");
	         trs.append("<td>"+emp.us_depid.de_name+"</td>");
	         trs.append("<td width='40'>"+emp.a_id.ar_sex+"</td>");
	         trs.append("<td>"+emp.us_phone+"</td>");
	         trs.append("<td>"+emp.a_id.ar_email+"</td>");
	        
	         $("#empbody").append(trs);
	       }
	        $("#pagediv").html("");
	        $("#count").html("");
	        $("#count").append("共有数据：<strong>"+pbean.totalRow+"</strong> 条");
	        $("#pagediv").append("<span>共"+pbean.totalRow+"条记录，当前显示第&nbsp;"+pbean.currpage+"&nbsp;页</div>");
	        var newul=$("<ul style='float:right;'></ul>");
	        //上一页
	         
	          newul.append("<li style='float:left;'><a href='javascript:void(0)' name='"+(pbean.currpage-1)+"' class='btn btn-primary radius'><span class='pagepre'><</span></a></li>");
	        
	        for( var i=1;i<=pbean.totalpage;i++)
	        {
	           newul.append("<li style='float:left;padding:5px;'><a href='javascript:void(0)' name='"+i+"'>&nbsp;"+i+"&nbsp;</a></li>");
	        }
	        
	        //下一页
	       
	         newul.append(" <li style='float:left;'><a href='javascript:void(0)'  name='"+(pbean.currpage+1)+"' class='btn btn-primary radius'><span class='pagenxt'>></span></a></li>");
	        $("#pagediv").append(newul);
		       
	       
	    });
	  }
	  
	</script>
	
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span class="c-gray en">&gt;</span> 用户管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
  <form id="queryform">
		部门：<select name="depid" id="dep" class="input-text" style="width:200px" >
		        <option value="0">--请选择一个部门--</option>
		     </select>
		姓名：<input type="text" name="name" class="input-text" style="width:120px" />
		<button type="button" class="btn btn-success radius" id="query" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
	  </form>
	<div class="mt-20">
	<table class="table table-border table-bordered table-hover table-bg">
		<thead>
			<tr class="text-c">
				
				<th width="80">ID</th>
				<th width="100">用户名</th>
				<th width="50">部门</th>
				<th width="40">性别</th>
				<th width="90">手机</th>
				<th width="150">邮箱</th>
				
			</tr>
		</thead>
		<tbody id="empbody">
		
		</tbody>
	</table>
	</div>
	<div id="pagediv"></div>
</div>



<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">

/*用户-添加*/
function member_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*用户-查看*/
function member_show(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*用户-停用*/
function member_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_start(this,id)" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>');
				$(obj).parents("tr").find(".td-status")('<span class="label label-defaunt radius">已停用</span>');
				$(obj).remove();
				layer.msg('已停用!',{icon: 5,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}

/*用户-启用*/
function member_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_stop(this,id)" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>');
				$(obj).parents("tr").find(".td-status")('<span class="label label-success radius">已启用</span>');
				$(obj).remove();
				layer.msg('已启用!',{icon: 6,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}
/*用户-编辑*/
function member_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*密码-修改*/
function change_password(title,url,id,w,h){
	layer_show(title,url,w,h);	
}
/*用户-删除*/
function member_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: 'emp/del.action',
			dataType: 'json',
			data:"id="+id,
			success: function(res){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.location.reload();//刷新父页面
				parent.layer.close(index);
			},
			error:function(res) {
				console.log(res.msg);
			},
		});		
	});
}
</script> 
</body>
</html>